package com.kedi.healthcenter.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kedi.healthcenter.service.OldlifeService;

/**
 * 
 *
 * @ClassName PcOldLifeController
 * @author: 陈辽逊
 * @date: 2019/7/13 12:07
 */
@Controller
public class OldlifeController {


	@Autowired
	public OldlifeService service;

	/**
	 * @Description: 查询全部床位信息
	 */
	@RequestMapping("/getoldlifeall")
	@ResponseBody
	public List<Map<String, Object>> getoldlifeall(int total_page,int limit) {
		if (total_page !=0 && limit !=0) {
			int page = (total_page - 1) * limit;
			return service.findBedList(page,limit);
		}else {
			return null;
		}
	}

	/**
	 * @Description: 根据价格返回床位信息
	 */
	@RequestMapping("/getoldprice")
	@ResponseBody
	public List<Map<String, Object>> selectoldlifepart(int minprice, int maxprice,int total_page,int limit) {
		if (maxprice != 0 && total_page !=0 && limit !=0 ) {
			int page = (total_page - 1) * limit;
			return service.oldprice(minprice, maxprice,page,limit);
		}else {
			return null;
		}
	}


	   /**
      * 方法实现说明  点赞+1
      * @author      ytw
      * @param			oldlifeid，puserid
      * @return
      * @exception
      * @date        2019/7/12 9:48
      */
      @RequestMapping(value="/updatePraise")
      @ResponseBody
      public int increasePraise(@RequestParam("oldlifeid") Integer oldlifeid,@RequestParam("puserid")Integer puserid){
		  if(oldlifeid<0&&puserid<0) {
			  throw new RuntimeException("传入的类型为负数");
		  }
		  HashMap<Object, Object> map = new HashMap<>(10);
		  map.put("oldlife_id",oldlifeid);
		  map.put("p_user_id",puserid);
		  return   service.updatePraise(map);
	  }



      /**
      * 方法实现说明  收藏+1
      * @author      ytw
      *@param		oldlifeid，puserid
      * @return
      * @exception
      * @date        2019/7/12 9:49
      */
	  @RequestMapping("/updateCollection")
	  @ResponseBody
	  public int increaseCollection(@RequestParam("oldlifeid") Integer oldlifeid,@RequestParam("puserid")Integer puserid){
		  if(oldlifeid<0&&puserid<0) {
			  throw new RuntimeException("传入的类型为负数");
		  }
		  HashMap<Object, Object> map = new HashMap<>(10);
		  map.put("oldlife_id",oldlifeid);
		  map.put("p_user_id",puserid);
		  return   service.updateCollection(map);
	  }

}
